package handler

import (
	"context"

	"github.com/micro/go-micro/util/log"

	sns "github.com/wufly/sns"
	ypclnt "github.com/yunpian/yunpian-go-sdk/sdk"
)

type Sns struct{}

// Call is a single request handler called via client.Call or the generated client code
func (e *Sns) Send(ctx context.Context, req *sns.Request, rsp *sns.Response) error {
	log.Log("Received Sns.Call request")
	rsp.Msg = "Hello " + req.Phone
	// 处理业务逻辑
	// 发送短信
	clnt := ypclnt.New("0d782d6b322644bb153d6d95c817a6e7")
	clnt.Tpl()
	param := ypclnt.NewParam(2)
	param[ypclnt.MOBILE] = req.Phone
	param[ypclnt.TEXT] = req.Context
	r := clnt.Sms().SingleSend(param)
	log.Log("短信发送结果:%v", r.Code)
	return nil
}
